package com.neulogistics.contrib.usercenter.api.controller;

import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import com.blackto.lib.mediat.core.IMediator;
import com.neulogistics.contrib.usercenter.api.application.query.IUserQueryService;
import com.neulogistics.contrib.usercenter.api.application.viewmodel.UserViewModel;
import com.neulogistics.contrib.usercenter.api.service.ThreadLocalService;
import com.neulogistics.contrib.usercenter.domain.model.aggregate.Role;
import com.neulogistics.contrib.usercenter.domain.repository.IRoleRepository;
import com.neulogistics.contrib.usercenter.domain.repository.IUserRepository;
import com.neulogistics.infrastructure.common.serviceresult.BaseResponse;
import com.neulogistics.infrastructure.common.serviceresult.ResultUtils;
import com.neulogistics.infrastructure.common.token.LoginUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Positive;

@RestController
@Api(tags = "角色管理")
@RequestMapping("/userCenter/menu")
public class RoleController {
    @Resource
    IRoleRepository roleRepository;

    @Resource
    IMediator mediator;


    @ApiOperation("根据用户userRole返回菜单")
    @GetMapping("/list/{userRole}")
    public BaseResponse<JSONArray> get(@PathVariable @NotNull Integer userRole){

        Role role = roleRepository.findByLevel(userRole);

        return ResultUtils.success(role.getRoleMenu());
    }

    @ApiOperation("根据token返回菜单")
    @GetMapping("/list")
    public BaseResponse<JSONArray> getByToken(){

        LoginUser loginUser = ThreadLocalService.loginUser.get();
        Role role = roleRepository.findByLevel(loginUser.userRole);

        return ResultUtils.success(role.getRoleMenu());
    }

}
